package son.nt.adapter;

import java.util.ArrayList;

import son.nt.R;
import son.nt.entities.Song;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class ListviewAdapter extends BaseAdapter{
	private Context mContext = null;
	private Song song;
	private ArrayList<Song> list;
	
	public ListviewAdapter(Context context, ArrayList<Song> list){
		super();
		mContext = context;
		this.list = list;
	}

	public int getCount() {
		return list.size();
	}

	public Object getItem(int arg0) {
		return null;
	}

	public long getItemId(int arg0) {
		return 0;
	}

	@SuppressLint({ "ResourceAsColor", "ResourceAsColor" }) public View getView(int position, View convertView, ViewGroup parent) {
		View view = null;
		if(convertView == null){
			LayoutInflater inflater = (LayoutInflater) mContext
							.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = inflater.inflate(R.layout.list_row, null);
			RelativeLayout mbody = (RelativeLayout) view.findViewById(R.id.row_background);
			TextView txtTitle = (TextView) view.findViewById(R.id.txtTitle);
			TextView txtArtist = (TextView) view.findViewById(R.id.txtArist);
			TextView txtDuration = (TextView) view.findViewById(R.id.txtDuration);
			ImageView thumbnail = (ImageView)view.findViewById(R.id.imgListImage);
			
			song = list.get(position);
			txtTitle.setText(song.getTitle());
			txtArtist.setText(song.getArtist());
			txtDuration.setText(song.getDuration());
			if(song.getThumbnail_url().startsWith("rihanna")){
				thumbnail.setImageResource(R.drawable.rihanna);
			}else if(song.getThumbnail_url().startsWith("adele")){
				thumbnail.setImageResource(R.drawable.adele);
			}else if(song.getThumbnail_url().startsWith("emi")){
				thumbnail.setImageResource(R.drawable.eminem);
			}else{
				thumbnail.setImageResource(R.drawable.rihanna);
			}
			
			if(position %2 == 0){
				mbody.setBackgroundResource(R.drawable.bg_2);
//				mbody.setBackgroundResource(android.R.color.holo_blue_dark);
			}else{
				mbody.setBackgroundResource(android.R.color.holo_orange_dark);
			}
		}
		return view;
	}

}
